﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Heaven.Graphics
{
    /// <summary>
    /// This class presents a GPU shader program
    /// </summary>
    public class Shader
    {
        /// <summary>
        /// Event occurs when a polygonal object has 
        /// been collected by GC (in other thread!)
        /// </summary>
        public event EventHandler GarbageCollected;

        /// <summary>
        /// HLSL shader code
        /// </summary>
        string source = null;

        // Hash number (as a matter of 
        // fact it is just time stamp, two 
        // object can't be created
        // in equal time)
        long hash;

        /// <summary>
        /// Hash code for this shader
        /// </summary>
        public long Hash
        {
            get { return hash; }
        }

        /// <summary>
        /// Source code
        /// </summary>
        public string Source
        {
            get { return source; }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="source">Source code</param>
        public Shader(string source)
        {
            this.source = source;
            // Hash number (as a matter of fact it is just 
            // time stamp, two object can't create in equal time)
            hash = System.Diagnostics.Stopwatch.GetTimestamp();
        }

        /// <summary>
        /// Finalizer
        /// </summary>
        ~Shader()
        {
            if (GarbageCollected != null) GarbageCollected(this, EventArgs.Empty);
        }
    }
}
